// parser.js
const cheerio = require('cheerio');

function parseNews(html, url) {
  const $ = cheerio.load(html);
  const title = $('title').text().trim();
  const content = $('.rich_media_content').text().trim().slice(0, 300); // 可拓展
  const time = $('meta[property="article:published_time"]').attr('content');
  const imageUrls = [];

  $('img').each((_, el) => {
    const src = $(el).attr('src');
    if (src) imageUrls.push(src);
  });

  return { title, content, time, imageUrls, url };
}

module.exports = parseNews;
